package com.kakaxi.mybilibili.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.bean.LiveConsiderItemBean;
import com.kakaxi.mybilibili.view.LinearMarginDecoration;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * 关注主播列表适配器
 * Created by kakaxi on 16/11/13.
 */

public class LiveConsiderRecyAdapter extends BaseQuickAdapter<LiveConsiderItemBean,
        BaseViewHolder> {

    public LiveConsiderRecyAdapter(List<LiveConsiderItemBean> data) {
        super(R.layout.item_recy_live_consider, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, LiveConsiderItemBean
            liveConsiderItemBean) {
        baseViewHolder
                .setText(R.id.txt_live_consider_name, liveConsiderItemBean.getName())
                .setText(R.id.txt_live_consider_area, liveConsiderItemBean.getAreaName())
                .setText(R.id.txt_live_consider_num, liveConsiderItemBean.getFansNum() + "");
        Glide.with(mContext).load(liveConsiderItemBean.getFace()).crossFade().into((ImageView)
                baseViewHolder.getView(R.id.civ_live_consider_face));
        TextView statusTxt = baseViewHolder.getView(R.id.txt_live_consider_status);
        if (liveConsiderItemBean.getLiveStatus() == 1) {
            statusTxt.setText("直播中");
            statusTxt.setBackgroundResource(R.color.colorPrimary);
        } else {
            statusTxt.setText("闲置中");
            statusTxt.setBackgroundResource(android.R.color.darker_gray);
        }

        TagFlowLayout tagFlowLayout = baseViewHolder.getView(R.id.tflayout_live_consider_tag);
        tagFlowLayout.setAdapter(new TagAdapter<String>(liveConsiderItemBean.getRoomTags()) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) LayoutInflater.from(mContext).inflate(R.layout
                        .item_tag_live_consider, parent, false);
                tv.setText(s);
                return tv;
            }

        });
    }


    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        // 设置列表的布局类型以及边距器
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(recyclerView
                .getContext());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new LinearMarginDecoration(recyclerView.getContext()));
    }
}
